package com.migu.utils

import java.security.MessageDigest

import org.apache.commons.codec.digest.DigestUtils
import sun.misc.BASE64Encoder

/**
  * Created by maguoyun on 2017/03/21.
  */
object BizUtils {

  //解析url
  def httpParse(urlString:String): Array[String] ={
    if (urlString == null || urlString.length() == 0) return null
//    http://mglive.migucloud.com/527/DQM6YK17_C0.m3u8
    val urlP: Array[String] = urlString.split("/")
     urlP
  }

  def md5(str: String): String = {
    val md5 = MessageDigest.getInstance("MD5")
    val base64en = new BASE64Encoder()
    base64en.encode(md5.digest(str.getBytes("utf-8")))
  }



  def main(args: Array[String]) {
    val url = "http://mglive.migucloud.com/527/DQM6YK17_C0.m3u8"
//    val url1 = "http://miguvod.lovev.com/514/DQM6YK17_C0.m3u8"
    val urlp: Array[String] =  httpParse(url)
//    val domain: String = urlp(2)
//    val urlp1: Array[String] =  httpParse(url1)
    println("domain:"+urlp(2)+" uid:"+urlp(3)+" channelid:"+urlp(4).split("\\.")(0))
//    println("domain:"+urlp1(2)+" uid:"+urlp1(3)+" channelid:"+urlp1(4))
    println(DigestUtils.md5Hex(urlp(2)))
  }

}


